window.onload = function(){
	this.getCityInfo();
	this.initCityJson();
	this.handleCityMenuClick();
}
/*获取当前城市*/ 
function getCityInfo(){
	// http://pv.sohu.com/cityjson
    // var returnCitySN = {"cip": "58.34.162.216", "cid": "310000", "cname": "上海市"};
	let oCityName = this.document.querySelector(".tool-left>.city>b");
	oCityName.innerText = returnCitySN["cname"];
}
/**/ 
function handleCityMenuClick(){
	//处理点击事件
	let oCity = document.querySelector(".city");
	oCity.onclick = function(){
		let oDiv = document.querySelector(".city>div");
		if(this.className.includes("active")){
			this.className = this.className.replace("active","");
			oDiv.style.display="none";
		}else{
			this.className = this.className + " active";
			oDiv.style.display="block";
		}
	}
}
/*初始化城市json数据*/ 
function initCityJson(){
	/*json文件url，本地的就写本地的位置，如果是服务器的就写服务器的路径*/
	var url = "/asset/json/city.json"
	var request = new XMLHttpRequest();
	/*设置请求方法与路径*/
	request.open("get", url);
	/*不发送数据到服务器*/
	request.send(null);
	/*XHR对象获取到返回信息后执行*/
	request.onload = ()=> {
		if (request.status == 200) {
			/*返回状态为200，即为数据获取成功*/
			var json = JSON.parse(request.responseText);
			this.initCityTemplate(json);
		}
	}
}
/*处理城市dom*/
function initCityTemplate(obj){
	let html = template("cityes",obj);
	let oCity = document.querySelector(".city");
	oCity.innerHTML = oCity.innerHTML + html;
}